

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using JTC.MiniCommerce.Core;
using JTC.MiniCommerce.Localization;
using JTC.MiniCommerce.Store;

namespace JTC.MiniCommerce.Web.admin {
  public partial class trackinglogs : System.Web.UI.Page {

    #region Page Events

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e) {
      try {
        SetTrackingLogsProperties();
        LoadCategoryBrowsingLog();
        LoadProductBrowsingLog();
      }
      catch (Exception ex) {
        Logger.Error(typeof(trackinglogs).Name + ".Page_Load", ex);
        Master.MessageCenter.DisplayCriticalMessage(LocalizationUtility.GetCriticalMessageText(ex.Message));
      }
    }

    /// <summary>
    /// Handles the ItemDataBound event of the dgProducts control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataGridItemEventArgs"/> instance containing the event data.</param>
    void dgProducts_ItemDataBound(object sender, DataGridItemEventArgs e) {
      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
        e.Item.Attributes.Add("onmouseover", "this.className = \"over\";");
        e.Item.Attributes.Add("onmouseout", "this.className = this.className.replace(\"over\", \"\");");
      }
    }

    /// <summary>
    /// Handles the ItemDataBound event of the dgCategory control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataGridItemEventArgs"/> instance containing the event data.</param>
    void dgCategory_ItemDataBound(object sender, DataGridItemEventArgs e) {
      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
        e.Item.Attributes.Add("onmouseover", "this.className = \"over\";");
        e.Item.Attributes.Add("onmouseout", "this.className = this.className.replace(\"over\", \"\");");
      }
    }

    #endregion

    #region Methods

    #region Private

    /// <summary>
    /// Sets the tracking logs properties.
    /// </summary>
    private void SetTrackingLogsProperties() {
      LocalizationUtility.AddLabelText(lblCategoryListing);
      LocalizationUtility.AddLabelText(lblProductListing);
      LocalizationUtility.AddLabelText(lblBrowsingLogListing);
      this.Title = LocalizationUtility.GetText("titleTrackingLogs");
    }

    /// <summary>
    /// Loads the product browsing log.
    /// </summary>
    private void LoadProductBrowsingLog() {
      DataSet dsProducts = new BrowsingLogController().FetchProductBrowsingLog();
      dgProducts.DataSource = dsProducts;
      dgProducts.ItemDataBound += new DataGridItemEventHandler(dgProducts_ItemDataBound);
      dgProducts.Columns[0].HeaderText = LocalizationUtility.GetText("hdrHits");
      dgProducts.Columns[1].HeaderText = LocalizationUtility.GetText("hdrName");
      dgProducts.DataBind();
    }

    /// <summary>
    /// Loads the category browsing log.
    /// </summary>
    private void LoadCategoryBrowsingLog() {
      DataSet dsCategories = new BrowsingLogController().FetchCategoryBrowsingLog();
      dgCategory.DataSource = dsCategories;
      dgCategory.ItemDataBound += new DataGridItemEventHandler(dgCategory_ItemDataBound);
      dgCategory.Columns[0].HeaderText = LocalizationUtility.GetText("hdrHits");
      dgCategory.Columns[1].HeaderText = LocalizationUtility.GetText("hdrName");
      dgCategory.DataBind();
    }

    #endregion

    #endregion

  }
}
